package org.springblade.tms.module.inquirysheet.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.tms.module.inquirysheet.base.InquirySheetAppService;
import org.springblade.tms.module.inquirysheet.base.InquirySheetService;
import org.springblade.tms.module.inquirysheet.vo.*;
import org.springblade.tms.module.userinfo.entity.TMUserInfo;
import org.springblade.tms.module.userinfo.service.IUserInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @projectName: BladeX
 * @package: org.springblade.tms.module.inquirysheet.controller
 * @className: InquirySheetAppController
 * @author: yr
 * @description: 询价单app
 * @date: 2022/6/28 17:45
 */
@RestController
@RequestMapping("Inquiry/InquirySheetApp")
@Api(value = "询价单app(新)-yr", tags = "询价单app(新)-yr")
public class InquirySheetAppController {
	@Resource
	private InquirySheetService inquirySheetService;
	@Resource
	private InquirySheetAppService inquirySheetAppService;
	@Resource
	private IUserInfoService userInfoService;

	/**
	 * 分页 询价单列表
	 */
	@ApiLog("询价单列表")
	@GetMapping("/list")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "询价单列表(新)", notes = "传入exceptionType")
	public R<IPage<InquirySheetRespVo>> list(InquirySheetReqVo inquirySheetReqVo, Query query) {
		return inquirySheetService.list(inquirySheetReqVo, query);
	}


	/**
	 * 询价单详情
	 */
	@ApiLog("询价单详情")
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "询价单详情(新)", notes = "传入id")
	public R<InquirySheetRespVo> detail(@RequestParam Long id) {
		return inquirySheetService.detail(id);
	}

	/**
	 * 询价单承运商绑定
	 */
	@ApiLog("询价单承运商报价")
	@PostMapping("/quotedPrice")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "询价单承运商报价(新)", notes = "传入id")
	public R<Boolean> quotedPrice(@RequestBody @Valid InquiryItemSaveVo inquiryItemSaveVo, @ApiParam("当前行数据id") @RequestParam Long id,
                                  @ApiParam("外贸时报价信息列表数据id") @RequestParam Long startId) {
		return inquirySheetService.quotedPrice(inquiryItemSaveVo, id, startId);
	}

	/**
	 * 询价单承运商绑定
	 */
	@ApiLog("询价单报价信息-承运商")
	@GetMapping("/priceList")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "询价单报价信息-承运商", notes = "传入id")
	public R<InquiryItemQueryVo> priceList(@RequestParam Long id) {
		return inquirySheetAppService.priceOne(id);
	}

	/**
	 * 询价单承运商绑定
	 *
	 * @return
	 */
	@ApiLog("议价详情")
	@GetMapping("/negotiationDetails")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "议价详情", notes = "传入id")
	public R<HistoricalQuotationVO> negotiationDetails(@RequestParam Long id) {
		return inquirySheetAppService.negotiationDetails(id);
	}

	/**
	 * 询价单承运商绑定
	 *
	 * @return
	 */
	@ApiLog("历史报价列表查询")
	@GetMapping("/historicalPriceList")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "历史报价列表查询(新)", notes = "传入id")
	public R<List<HistoricalQuotationVO>> historicalPriceList(@RequestParam Long id) {
		return inquirySheetService.historicalPriceList(id);
	}

	/**
	 * 询价单承运商绑定
	 */
	@ApiLog("外贸报价详情列表")
	@GetMapping("/priceDetailList")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "外贸报价详情列表(新)", notes = "传入id")
	public R<List<InquiryItemQueryVo>> priceDetailList(@ApiParam("询价单id") @RequestParam Long id) {
		Long userId = AuthUtil.getUser().getUserId();
		TMUserInfo tmUserInfo = userInfoService.lambdaQuery().eq(TMUserInfo::getParentId, userId).one();
		return inquirySheetService.priceDetailList(id, tmUserInfo.getTmId());
	}

	/**
	 * 询价单承运商绑定
	 */
	@ApiLog("内贸和散货查看排行")
	@GetMapping("/viewRanking")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "内贸和散货查看排行", notes = "传入id")
	public R<ViewRankingVO> viewRanking(@RequestParam Long id) {
		return inquirySheetAppService.viewRanking(id);
	}

	/**
	 * 询价单承运商绑定
	 */
	@ApiLog("外贸报价单个详情")
	@GetMapping("/priceDetail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "外贸报价单个详情", notes = "传入id")
	public R<InquiryItemQueryVo> priceDetail(@RequestParam Long id) {
		return inquirySheetAppService.priceDetail(id);
	}

}
